package logic

import (
	"context"
	"goodsrpc/mysql"

	"goodsrpc/goods"
	"goodsrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type HouseListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewHouseListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HouseListLogic {
	return &HouseListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *HouseListLogic) HouseList(in *goods.HouseListRequest) (*goods.HouseListResponse, error) {
	// todo: add your logic here and delete this line
	var h mysql.House
	list, err := h.HouseList(in.PriceFront, in.PriceAfter)
	if err != nil {
		return nil, err
	}
	var Houselist []*goods.HouseList
	for _, i := range list {
		houseList := goods.HouseList{
			Name:        i.Name,
			Price:       uint64(i.Price),
			FacePrice:   uint64(i.FacePrice),
			HouseNumber: i.HouseNumber,
			ListingTime: i.ListingTime,
			State:       i.State,
			UserId:      i.UserId,
		}
		Houselist = append(Houselist, &houseList)
	}

	return &goods.HouseListResponse{
		List: Houselist,
	}, nil
}
